package com.api.regression.group.uploaddocumentnewversion;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.test.context.ContextConfiguration;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import com.api.test.AbstractApiTest;
import com.zyncro.api.IGroupApiService;
import com.zyncro.api.exceptions.ZyncroApiException;

@ContextConfiguration(locations = { "classpath:/group/group-upload.xml" })
public class UploadNewDocumentNotParticipant extends AbstractApiTest {

	@Value("#{group_toUpload[notParticipant].appId}")
	private String userUrn;

	@Value("#{group_toUpload[notParticipant].password}")
	private String userPassword;

	@Value("#{group_toUpload.urn}")
	private String groupUrn;

	@Value("#{group_toUpload.documentUrn}")
	private String groupDocumentUrn;

	@Value("#{group_toUpload.documentVersionUrn}")
	private String documentVersionUrn;

	@BeforeClass
	protected void setParameters() throws Exception {

		getApi().login(userUrn, userPassword);
	}

	@Test(expectedExceptions = { ZyncroApiException.class })
	public void testUpload() throws ZyncroApiException, FileNotFoundException {

		File file = new File("FileName.txt");

		Long length = file.length();
		String fileName = file.getName();
		FileInputStream inputStream = new FileInputStream(file);

		String description = null;
		String comment = null;

		getApi().getService(IGroupApiService.class).uploadDocumentNewVersion(groupUrn, groupDocumentUrn, documentVersionUrn, getApi().getAccessKey(),
				description, comment, fileName, length, inputStream);
	}
}
